<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Open Event Machine API: test_appl_event_group.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Open Event Machine API
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('test_appl_event_group_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">test_appl_event_group.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> *   Copyright (c) 2012, Nokia Siemens Networks</span></div>
<div class="line"><span class="comment"> *   All rights reserved.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> *   Redistribution and use in source and binary forms, with or without</span></div>
<div class="line"><span class="comment"> *   modification, are permitted provided that the following conditions are met:</span></div>
<div class="line"><span class="comment"> *       * Redistributions of source code must retain the above copyright</span></div>
<div class="line"><span class="comment"> *         notice, this list of conditions and the following disclaimer.</span></div>
<div class="line"><span class="comment"> *       * Redistributions in binary form must reproduce the above copyright</span></div>
<div class="line"><span class="comment"> *         notice, this list of conditions and the following disclaimer in the</span></div>
<div class="line"><span class="comment"> *         documentation and/or other materials provided with the distribution.</span></div>
<div class="line"><span class="comment"> *       * Neither the name of Nokia Siemens Networks nor the</span></div>
<div class="line"><span class="comment"> *         names of its contributors may be used to endorse or promote products</span></div>
<div class="line"><span class="comment"> *         derived from this software without specific prior written permission.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span></div>
<div class="line"><span class="comment"> *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></div>
<div class="line"><span class="comment"> *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span></div>
<div class="line"><span class="comment"> *   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY</span></div>
<div class="line"><span class="comment"> *   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span></div>
<div class="line"><span class="comment"> *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span></div>
<div class="line"><span class="comment"> *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span></div>
<div class="line"><span class="comment"> *   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span></div>
<div class="line"><span class="comment"> *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span></div>
<div class="line"><span class="comment"> *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="event__machine_8h.html" title="Event Machine API v1.0.">event_machine.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="event__machine__group_8h.html" title="Event Machine optional fork-join helper.">event_machine_group.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;environment.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;example.h&quot;</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Test configuration</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define DATA_EVENTS           128</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#define DATA_PER_EVENT        1024</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#define EVENT_GROUP_INCREMENT 1</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#define MAX_NBR_OF_CORES      256</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#define DELAY_SPIN_COUNT      50000000</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Note: The error macros below are NOT proper event machine error handling mechanisms.</span></div>
<div class="line"><span class="comment"> * For better error handling see the API funcs: em_error(), em_register_error_handler(),  </span></div>
<div class="line"><span class="comment"> * em_eo_register_error_handler() etc.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="preprocessor">#define ERROR_PRINT(...)     {fprintf(stderr, &quot;\nAPPL ERROR: %s %s(line:%d) - EM-core%02i: &quot;, __FILE__, __func__, __LINE__, em_core_id()); \</span></div>
<div class="line"><span class="preprocessor">                              fprintf(stderr, __VA_ARGS__); fprintf(stderr, &quot;\n\n&quot;); abort();}</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#define IS_ERROR(cond, ...)    \</span></div>
<div class="line"><span class="preprocessor">  if(ENV_UNLIKELY( (cond) )) { \</span></div>
<div class="line"><span class="preprocessor">    ERROR_PRINT(__VA_ARGS__);  \</span></div>
<div class="line"><span class="preprocessor">  }</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line"><span class="preprocessor">  #define MSG_START 1</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">  #define MSG_DATA  2</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">  #define MSG_DONE  3</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line">  uint64_t  msg;</div>
<div class="line">  </div>
<div class="line">  uint64_t  start_cycles;</div>
<div class="line">  </div>
<div class="line">  uint64_t  increment;</div>
<div class="line">  </div>
<div class="line">  uint8_t  *data_ptr;</div>
<div class="line"></div>
<div class="line">} event_group_test_t;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">union</span></div>
<div class="line">{</div>
<div class="line">  <span class="keyword">struct</span></div>
<div class="line">  {</div>
<div class="line">    <a class="code" href="event__machine__group_8h.html#a199db840eb3b542e407c975b5b3f3362" title="Event group id.">em_event_group_t</a> event_group;</div>
<div class="line">    </div>
<div class="line">    <span class="keywordtype">int</span>              event_count;</div>
<div class="line">    </div>
<div class="line">    uint64_t         acc;</div>
<div class="line">    </div>
<div class="line">    uint64_t         total_cycles;</div>
<div class="line">    </div>
<div class="line">    uint64_t         total_rounds;</div>
<div class="line">  };</div>
<div class="line">  </div>
<div class="line">  uint8_t u8[ENV_CACHE_LINE_SIZE];  </div>
<div class="line">  </div>
<div class="line">} eo_context_t;</div>
<div class="line"></div>
<div class="line">COMPILE_TIME_ASSERT(<span class="keyword">sizeof</span>(eo_context_t) == ENV_CACHE_LINE_SIZE, EVENT_GROUP_TEST_EO_CONTEXT_SIZE_ERROR);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">union </span></div>
<div class="line">{</div>
<div class="line">  uint64_t rcv_ev_cnt;</div>
<div class="line">  </div>
<div class="line">  uint8_t u8[ENV_CACHE_LINE_SIZE];</div>
<div class="line">  </div>
<div class="line">} core_stat_t;</div>
<div class="line"></div>
<div class="line">COMPILE_TIME_ASSERT(<span class="keyword">sizeof</span>(core_stat_t) == ENV_CACHE_LINE_SIZE, CORE_STAT_T_SIZE_ERROR);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line">  eo_context_t  event_group_test_eo_context  ENV_CACHE_LINE_ALIGNED;</div>
<div class="line">  </div>
<div class="line">  core_stat_t  core_stats[MAX_NBR_OF_CORES]  ENV_CACHE_LINE_ALIGNED;</div>
<div class="line">  </div>
<div class="line">  uint8_t  event_group_test_data[DATA_EVENTS * DATA_PER_EVENT]  ENV_CACHE_LINE_ALIGNED;  </div>
<div class="line">  </div>
<div class="line">} egrp_shm_t;</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> ENV_LOCAL egrp_shm_t *egrp_shm = NULL;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Local function prototypes</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">egroup_start(<span class="keywordtype">void</span>* eo_context, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo);</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">egroup_stop(<span class="keywordtype">void</span>* eo_context, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo);</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">egroup_receive(<span class="keywordtype">void</span>* eo_context, em_event_t event, <a class="code" href="event__machine__types_8h.html#a2f5b3fb43add8103da34b52cc1d0f2cc" title="Event type.">em_event_type_t</a> type, <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue, <span class="keywordtype">void</span>* q_ctx);</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">delay_spin(<span class="keyword">const</span> uint64_t spin_count);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span></div>
<div class="line">test_init(appl_conf_t *<span class="keyword">const</span> appl_conf)</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a>             eo;</div>
<div class="line">  eo_context_t*       eo_ctx;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a>          queue;</div>
<div class="line">  em_event_t          event;</div>
<div class="line">  event_group_test_t* egroup_test;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a>         ret;</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a>         eo_start_ret; <span class="comment">// return value from the EO&#39;s start function &#39;group_start&#39;</span></div>
<div class="line">  </div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(<a name="a0"></a><a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>() == 0) {</div>
<div class="line">    egrp_shm = env_shared_reserve(<span class="stringliteral">&quot;EGrpSharedMem&quot;</span>, <span class="keyword">sizeof</span>(egrp_shm_t));</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span> {</div>
<div class="line">    egrp_shm = env_shared_lookup(<span class="stringliteral">&quot;EGrpSharedMem&quot;</span>);</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">if</span>(egrp_shm == NULL) {</div>
<div class="line">    <a name="a1"></a><a class="code" href="event__machine_8h.html#a1d45cd3fa718f99bce956904b5e081de" title="Report an error.">em_error</a>(EM_ERROR_SET_FATAL(0xec0de), 0xdead, <span class="stringliteral">&quot;EventGroup test init failed on EM-core: %u\n&quot;</span>, <a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>());</div>
<div class="line">  }</div>
<div class="line">    </div>
<div class="line"></div>
<div class="line">  <span class="comment">/*</span></div>
<div class="line"><span class="comment">   * Rest of the initializations only on one EM-core, return on all others.</span></div>
<div class="line"><span class="comment">   */</span>  </div>
<div class="line">  <span class="keywordflow">if</span>(<a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>() != 0)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">return</span>;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  printf(<span class="stringliteral">&quot;\n**********************************************************************\n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;EM APPLICATION: &#39;%s&#39; initializing: \n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;  %s: %s() - EM-core:%i \n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;  Application running on %d EM-cores (procs:%d, threads:%d).&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;\n**********************************************************************\n&quot;</span></div>
<div class="line">         <span class="stringliteral">&quot;\n&quot;</span></div>
<div class="line">         ,</div>
<div class="line">         appl_conf-&gt;name,</div>
<div class="line">         NO_PATH(__FILE__), __func__,</div>
<div class="line">         <a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>(),</div>
<div class="line">         <a name="a2"></a><a class="code" href="event__machine_8h.html#a84fa6ec801b82a586ff5e31693d3deb8" title="The number of cores running within the same EM instance (sharing the EM state).">em_core_count</a>(),</div>
<div class="line">         appl_conf-&gt;num_procs,</div>
<div class="line">         appl_conf-&gt;num_threads);</div>
<div class="line">         </div>
<div class="line">  </div>
<div class="line">  <span class="comment">/*</span></div>
<div class="line"><span class="comment">   * Create the event group test EO and a parallel queue, add the queue to the EO</span></div>
<div class="line"><span class="comment">   */</span></div>
<div class="line">  eo_ctx = &amp;egrp_shm-&gt;event_group_test_eo_context;</div>
<div class="line">  </div>
<div class="line">  eo    = <a name="a3"></a><a class="code" href="event__machine_8h.html#a196c7caa1177575fd424e9a0d2854da6" title="Create Execution Object (EO).">em_eo_create</a>(<span class="stringliteral">&quot;group test appl&quot;</span>, egroup_start, NULL, egroup_stop, NULL, egroup_receive, eo_ctx);  </div>
<div class="line">  queue = <a name="a4"></a><a class="code" href="event__machine_8h.html#a15c0cb536f8c7c01692ccea07908944a" title="Create a new queue with a dynamic queue id.">em_queue_create</a>(<span class="stringliteral">&quot;group test parallelQ&quot;</span>, EM_QUEUE_TYPE_PARALLEL, EM_QUEUE_PRIO_NORMAL, EM_QUEUE_GROUP_DEFAULT);</div>
<div class="line"></div>
<div class="line">  ret = <a name="a5"></a><a class="code" href="event__machine_8h.html#a681c9d79f7ca5c0590030f74357472c0" title="Add a queue to an EO.">em_eo_add_queue</a>(eo, queue);</div>
<div class="line">  IS_ERROR(ret != <a name="a6"></a><a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>, <span class="stringliteral">&quot;EO or queue creation failed (%u). EO: %&quot;</span><a name="a7"></a><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a name="a8"></a><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot;\n&quot;</span>, ret, eo, queue);</div>
<div class="line">  </div>
<div class="line">  ret = <a name="a9"></a><a class="code" href="event__machine_8h.html#adcbab74b22ffcb629bdf797704ac2706" title="Enable event scheduling for the queue.">em_queue_enable</a>(queue);</div>
<div class="line">  IS_ERROR(ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>, <span class="stringliteral">&quot;Queue enable failed (%u). EO: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot;\n&quot;</span>, ret, eo, queue);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Start the EO (triggers the EO&#39;s start function &#39;group_start&#39;)</span></div>
<div class="line">  ret = <a name="a10"></a><a class="code" href="event__machine_8h.html#a97445f266a00782bb23fc2c464533d6d" title="Start Execution Object (EO).">em_eo_start</a>(eo, &amp;eo_start_ret, 0, NULL);</div>
<div class="line">  </div>
<div class="line">  IS_ERROR((ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>) || (eo_start_ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>),</div>
<div class="line">           <span class="stringliteral">&quot;em_eo_start() failed! EO: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot;, ret: %u, EO-start-ret: %u \n&quot;</span>, eo, ret, eo_start_ret);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">  <span class="keyword">event</span> = <a name="a11"></a><a class="code" href="event__machine_8h.html#a22fcb41f303628eebe4f0b45b6c64ab0" title="Allocate an event.">em_alloc</a>(<span class="keyword">sizeof</span>(event_group_test_t), EM_EVENT_TYPE_SW, EM_POOL_DEFAULT);</div>
<div class="line">  IS_ERROR(event == EM_EVENT_UNDEF, <span class="stringliteral">&quot;Event allocation failed! \n&quot;</span>);</div>
<div class="line">  </div>
<div class="line"></div>
<div class="line">  egroup_test = em_event_pointer(event);</div>
<div class="line">  </div>
<div class="line">  egroup_test-&gt;msg = MSG_START;</div>
<div class="line"></div>
<div class="line">  ret = <a name="a12"></a><a class="code" href="event__machine_8h.html#aca4584a01b71429dfbb045342454b464" title="Send an event to a queue.">em_send</a>(event, queue);</div>
<div class="line">  IS_ERROR(ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>, <span class="stringliteral">&quot;Event send failed (%u)! queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, ret, queue);</div>
<div class="line">}  </div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">egroup_start(<span class="keywordtype">void</span>* eo_context, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo)</div>
<div class="line">{</div>
<div class="line">  eo_context_t* eo_ctx = eo_context;</div>
<div class="line">  </div>
<div class="line">  (void) memset(eo_ctx, 0, <span class="keyword">sizeof</span>(eo_context_t));</div>
<div class="line"></div>
<div class="line">  eo_ctx-&gt;event_group = <a name="a13"></a><a class="code" href="event__machine__group_8h.html#a59755895fbc8f370c6904610326b2594" title="Create new event group id for fork-join.">em_event_group_create</a>();</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span>(eo_ctx-&gt;event_group == <a name="a14"></a><a class="code" href="event__machine__group_8h.html#adb766a36099bdc633d8aa36e82e889a2" title="Invalid event group.">EM_EVENT_GROUP_UNDEF</a>) {</div>
<div class="line">    <span class="keywordflow">return</span> EM_ERR_ALLOC_FAILED;</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line">  (void) memset(egrp_shm-&gt;core_stats, 0, <span class="keyword">sizeof</span>(egrp_shm-&gt;core_stats));</div>
<div class="line">  </div>
<div class="line">  printf(<span class="stringliteral">&quot;EO:%&quot;</span><a class="code" href="event__machine__types_8h.html#a0bf4a25d46e18ee918e684e5deb27fa4" title="em_eo_t printf format">PRI_EO</a><span class="stringliteral">&quot; - event group %&quot;</span><a name="a15"></a><a class="code" href="event__machine__group_8h.html#adca2f2f8040040218a3ec6795a9f1864" title="em_event_group_t printf format">PRI_EGRP</a><span class="stringliteral">&quot; created\n&quot;</span>, eo, eo_ctx-&gt;event_group);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Require &#39;DATA_EVENTS&#39; sent using the event_group before a notification, see em_event_group_apply() later</span></div>
<div class="line">  eo_ctx-&gt;event_count = DATA_EVENTS;</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a></div>
<div class="line">egroup_stop(<span class="keywordtype">void</span>* eo_context, <a class="code" href="event__machine__types_8h.html#a1d373bd8469414626259c3ea14b5ee2a" title="Execution Object identifier.">em_eo_t</a> eo)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">return</span> <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">egroup_receive(<span class="keywordtype">void</span>* eo_context, em_event_t event, <a class="code" href="event__machine__types_8h.html#a2f5b3fb43add8103da34b52cc1d0f2cc" title="Event type.">em_event_type_t</a> type, <a class="code" href="event__machine__types_8h.html#a43cb5a167efa542d81180a54915d99bf" title="Queue identifier.">em_queue_t</a> queue, <span class="keywordtype">void</span>* q_ctx)</div>
<div class="line">{</div>
<div class="line">  event_group_test_t* egroup_test;</div>
<div class="line">  <a name="_a16"></a><a class="code" href="structem__notif__t.html" title="Event.">em_notif_t</a>          notif_tbl[1];</div>
<div class="line">  <a class="code" href="event__machine__types_8h.html#a125a101c5db94235eb758c8c32ab2628" title="Error/Status code.">em_status_t</a>         ret;</div>
<div class="line">  uint64_t            diff;</div>
<div class="line">  uint64_t            sum;</div>
<div class="line">  <span class="keywordtype">int</span>                 i;</div>
<div class="line">  eo_context_t*       eo_ctx = eo_context;</div>
<div class="line"></div>
<div class="line">  egroup_test = em_event_pointer(event);</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">switch</span>(egroup_test-&gt;msg)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">case</span> MSG_START:    </div>
<div class="line">      {</div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         * (Re)start the test by configuring the event group, allocating all data events and</span></div>
<div class="line"><span class="comment">         * then sending (with event gourp) all events back to itself.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">         </div>
<div class="line">        printf(<span class="stringliteral">&quot;\n&quot;</span> <span class="stringliteral">&quot;Start.&quot;</span> <span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line">        </div>
<div class="line">        eo_ctx-&gt;acc = 0;</div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Re-use the start event as the notification event</span></div>
<div class="line">        egroup_test-&gt;msg          = MSG_DONE;</div>
<div class="line">        egroup_test-&gt;data_ptr     = NULL;</div>
<div class="line">        egroup_test-&gt;start_cycles = env_get_cycle();</div>
<div class="line">        egroup_test-&gt;increment    = 0;</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// The notification &#39;event&#39; should be sent to &#39;queue&#39; when done</span></div>
<div class="line">        notif_tbl[0].<a name="a17"></a><a class="code" href="structem__notif__t.html#af11de4e82ee78d6222a18ba93ffefa11" title="User defined notification event.">event</a> = event;</div>
<div class="line">        notif_tbl[0].<a name="a18"></a><a class="code" href="structem__notif__t.html#a1264d8b918729d1c703571289ea56f25" title="Destination queue.">queue</a> = queue;</div>
<div class="line">        </div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         * Request one notification event when &#39;eo_ctx-&gt;event_count&#39; events from &#39;eo_ctx-&gt;event_group&#39; have been received.</span></div>
<div class="line"><span class="comment">         * Note that the em_event_group_increment() functionality is used in the event:MSG_DATA processing so</span></div>
<div class="line"><span class="comment">         * the total number of events received will be larger than &#39;eo_ctx-&gt;event_count&#39; before the notification</span></div>
<div class="line"><span class="comment">         * &#39;MSG_DONE&#39; is received.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        ret = <a name="a19"></a><a class="code" href="event__machine__group_8h.html#a9b73bd7f58e2c0944e46af3753f2bbba" title="Apply event group configuration.">em_event_group_apply</a>(eo_ctx-&gt;event_group, eo_ctx-&gt;event_count, 1, notif_tbl);</div>
<div class="line">        IS_ERROR(ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>, <span class="stringliteral">&quot;em_event_group_apply() failed (%u)! \n&quot;</span>, ret);</div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Allocate &#39;eo_ctx-&gt;event_count&#39; number of DATA events and send using the event group</span></div>
<div class="line">        <span class="comment">// to trigger the notification event configured above with em_event_group_apply()</span></div>
<div class="line">        <span class="keywordflow">for</span>(i = 0; i &lt; eo_ctx-&gt;event_count; i++)</div>
<div class="line">        {</div>
<div class="line">          em_event_t          data;</div>
<div class="line">          event_group_test_t* group_test_2;</div>
<div class="line">        </div>
<div class="line">          data = <a class="code" href="event__machine_8h.html#a22fcb41f303628eebe4f0b45b6c64ab0" title="Allocate an event.">em_alloc</a>(<span class="keyword">sizeof</span>(event_group_test_t), EM_EVENT_TYPE_SW, EM_POOL_DEFAULT);</div>
<div class="line">          IS_ERROR(data == EM_EVENT_UNDEF, <span class="stringliteral">&quot;Event allocation failed! \n&quot;</span>);</div>
<div class="line">          </div>
<div class="line">          group_test_2 = em_event_pointer(data);</div>
<div class="line">          </div>
<div class="line">          group_test_2-&gt;msg          = MSG_DATA;</div>
<div class="line">          group_test_2-&gt;data_ptr     = &amp;egrp_shm-&gt;event_group_test_data[i*DATA_PER_EVENT];</div>
<div class="line">          group_test_2-&gt;start_cycles = 0;</div>
<div class="line">          group_test_2-&gt;increment    = EVENT_GROUP_INCREMENT; <span class="comment">// how many times to increment and re-send</span></div>
<div class="line">          </div>
<div class="line">          <span class="comment">// Send events using the event group.</span></div>
<div class="line">          <a name="a20"></a><a class="code" href="event__machine__group_8h.html#a4ac26c1e7c556eaec111ec33e8ff95dd" title="Send event with group number.">em_send_group</a>(data, queue, eo_ctx-&gt;event_group);</div>
<div class="line">        }</div>
<div class="line">      }</div>
<div class="line">      <span class="keywordflow">break</span>;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">case</span> MSG_DATA:</div>
<div class="line">      {</div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         * Do some dummy data processing:</span></div>
<div class="line"><span class="comment">         * Calculate a sum over the event and increment a shared variable.</span></div>
<div class="line"><span class="comment">         * For a correct result the shared variable &#39;eo_ctx-&gt;acc&#39; should be updated</span></div>
<div class="line"><span class="comment">         * using an atomic-add because the used queue type is parallel.</span></div>
<div class="line"><span class="comment">         * Don&#39;t care about the result however, only prevent the optimizer </span></div>
<div class="line"><span class="comment">         * from removing the data processing loop.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        sum = 0;</div>
<div class="line">        </div>
<div class="line">        <span class="keywordflow">for</span>(i = 0; i &lt; DATA_PER_EVENT; i++)</div>
<div class="line">        {</div>
<div class="line">          sum += egroup_test-&gt;data_ptr[i];</div>
<div class="line">        }</div>
<div class="line">        </div>
<div class="line">        eo_ctx-&gt;acc += sum;</div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        <span class="comment">// update the count of data events received on this core</span></div>
<div class="line">        egrp_shm-&gt;core_stats[<a class="code" href="event__machine_8h.html#a13d21af31382ec2c3d45010645707e9c" title="Logical core id.">em_core_id</a>()].rcv_ev_cnt += 1;</div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         * Test the em_event_group_increment() functionality.</span></div>
<div class="line"><span class="comment">         * Note that the total number of events received will become larger than</span></div>
<div class="line"><span class="comment">         * &#39;eo_ctx-&gt;event_count&#39; before the notification &#39;MSG_DONE&#39; is received.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        <span class="keywordflow">if</span>(egroup_test-&gt;increment)</div>
<div class="line">        {</div>
<div class="line">          <a class="code" href="event__machine__group_8h.html#a199db840eb3b542e407c975b5b3f3362" title="Event group id.">em_event_group_t</a> event_group;</div>
<div class="line">        </div>
<div class="line">          egroup_test-&gt;increment--;</div>
<div class="line">        </div>
<div class="line">          <span class="comment">// increment event count in group</span></div>
<div class="line">          (void) <a name="a21"></a><a class="code" href="event__machine__group_8h.html#ad4b2641ae20038924337e810b1ed91c2" title="Increment event group count.">em_event_group_increment</a>(1);</div>
<div class="line">        </div>
<div class="line">          <span class="comment">// get the current event group</span></div>
<div class="line">          event_group = <a name="a22"></a><a class="code" href="event__machine__group_8h.html#aa14004a7be775865f6bfe66fca8cfbc3" title="Current event group.">em_event_group_current</a>();</div>
<div class="line">        </div>
<div class="line">          <span class="comment">// re-send event using the event group</span></div>
<div class="line">          (void) <a class="code" href="event__machine__group_8h.html#a4ac26c1e7c556eaec111ec33e8ff95dd" title="Send event with group number.">em_send_group</a>(event, queue, event_group);</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span></div>
<div class="line">        {</div>
<div class="line">          <span class="comment">// free event</span></div>
<div class="line">          <a name="a23"></a><a class="code" href="event__machine_8h.html#ad4f97ba217518d967f8078c56023c4d4" title="Free an event.">em_free</a>(event);</div>
<div class="line">        }</div>
<div class="line">      }</div>
<div class="line">      <span class="keywordflow">break</span>;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">case</span> MSG_DONE:</div>
<div class="line">      {</div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         * Notification event received!</span></div>
<div class="line"><span class="comment">         * </span></div>
<div class="line"><span class="comment">         * Calulate the number of cycles it took and restart the test.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        uint64_t     rcv_ev_cnt = 0;</div>
<div class="line">        uint64_t     cfg_ev_cnt;</div>
<div class="line">        </div>
<div class="line">         </div>
<div class="line">        <span class="comment">// Calculate results. Ignore first round because of cold caches.</span></div>
<div class="line">        diff = env_get_cycle() - egroup_test-&gt;start_cycles;</div>
<div class="line">      </div>
<div class="line">        <span class="keywordflow">if</span>(eo_ctx-&gt;total_rounds == 0) {</div>
<div class="line">          <span class="comment">/* Ignore */</span></div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(eo_ctx-&gt;total_rounds == 1) {</div>
<div class="line">          eo_ctx-&gt;total_cycles += 2*diff;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> {</div>
<div class="line">          eo_ctx-&gt;total_cycles += diff;</div>
<div class="line">        }</div>
<div class="line">      </div>
<div class="line">        eo_ctx-&gt;total_rounds++;</div>
<div class="line">      </div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Sum up the amount of data events processed on each core </span></div>
<div class="line">        <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="event__machine_8h.html#a84fa6ec801b82a586ff5e31693d3deb8" title="The number of cores running within the same EM instance (sharing the EM state).">em_core_count</a>(); i++) {</div>
<div class="line">          rcv_ev_cnt += egrp_shm-&gt;core_stats[i].rcv_ev_cnt;</div>
<div class="line">        }</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// The expected number of data events processed to trigger a notification event</span></div>
<div class="line">        cfg_ev_cnt = (DATA_EVENTS * (1 + EVENT_GROUP_INCREMENT));</div>
<div class="line">      </div>
<div class="line">        <span class="comment">// Verify that the amount of received data events prior to this notification event is correct</span></div>
<div class="line">        IS_ERROR(rcv_ev_cnt != cfg_ev_cnt, </div>
<div class="line">                 <span class="stringliteral">&quot;Incorrect amount of data events prior to notification: %&quot;</span>PRIu64<span class="stringliteral">&quot; != %&quot;</span>PRIu64<span class="stringliteral">&quot;! \n&quot;</span>,</div>
<div class="line">                 rcv_ev_cnt, cfg_ev_cnt);</div>
<div class="line">        </div>
<div class="line">        </div>
<div class="line">        <span class="comment">// OK, print results</span></div>
<div class="line">        printf(<span class="stringliteral">&quot;Done. Notification event received after %&quot;</span>PRIu64<span class="stringliteral">&quot; data events. Cycles curr:%&quot;</span>PRIu64<span class="stringliteral">&quot;, ave:%&quot;</span>PRIu64<span class="stringliteral">&quot; \n&quot;</span>,</div>
<div class="line">               rcv_ev_cnt, diff, eo_ctx-&gt;total_cycles / eo_ctx-&gt;total_rounds);        </div>
<div class="line">      </div>
<div class="line">         </div>
<div class="line">        <span class="comment">// Restart the test after &quot;some cycles&quot; of delay</span></div>
<div class="line">        delay_spin(DELAY_SPIN_COUNT);</div>
<div class="line">        </div>
<div class="line">        (void) memset(egrp_shm-&gt;core_stats, 0, <span class="keyword">sizeof</span>(egrp_shm-&gt;core_stats));</div>
<div class="line">        </div>
<div class="line">        egroup_test-&gt;msg = MSG_START;</div>
<div class="line">      </div>
<div class="line">        ret = <a class="code" href="event__machine_8h.html#aca4584a01b71429dfbb045342454b464" title="Send an event to a queue.">em_send</a>(event, queue);</div>
<div class="line">        IS_ERROR(ret != <a class="code" href="event__machine__types_8h.html#a03546e6a7e93665c52d479831e0a6dca" title="Operation successful.">EM_OK</a>, <span class="stringliteral">&quot;Event send failed (%u)! queue: %&quot;</span><a class="code" href="event__machine__types_8h.html#a0331964318f921644a88d3cc38c122e5" title="em_queue_t printf format">PRI_QUEUE</a><span class="stringliteral">&quot; \n&quot;</span>, ret, queue);</div>
<div class="line">      }</div>
<div class="line">      <span class="keywordflow">break</span>;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">default</span>:</div>
<div class="line">      IS_ERROR(1, <span class="stringliteral">&quot;Bad msg (%&quot;</span>PRIu64<span class="stringliteral">&quot;)! \n&quot;</span>, egroup_test-&gt;msg);</div>
<div class="line">  };</div>
<div class="line"></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div>
<div class="line">delay_spin(<span class="keyword">const</span> uint64_t spin_count)</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">volatile</span> uint64_t dummy = 0;</div>
<div class="line">  uint64_t          i;</div>
<div class="line">  </div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">for</span>(i = 0; i &lt; spin_count; i++) {</div>
<div class="line">    dummy++;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Aug 7 2013 15:17:39 for Open Event Machine API by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li>
  </ul>
</div>
</body>
</html>
